/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package models;

import java.util.*;
import javax.persistence.*;
import play.data.binding.As;
import play.data.validation.*;
import play.db.jpa.*;

/**
 *
 * @author GJean
 */
@Entity
@Table(name = "users")
public class User extends Model {

    @Required
    public String firstname;
    @Required
    public String lastname;
    @As("dd/MM/yyyy")
    @Required
    public Date birthday;
    @Required
    public String avatar;
    @Required
    public String adress;
    @Required
    public String phonenumber;
    @Required
    @Email
    public String email;
    @Required
    public String username;
    @Required
    @Password
    public String password;
    @OneToOne
    @Required
    public Group groups;

    public User(
            String firstname,
            String lastname,
            @As("dd/MM/yyyy") Date birthday,
            String avatar,
            String adress,
            String phonenumber,
            String email,
            String username,
            String password,
            Group groups) {


        this.firstname = firstname;
        this.lastname = lastname;
        this.birthday = birthday;
        this.avatar = avatar;
        this.adress = adress;
        this.phonenumber = phonenumber;
        this.email = email;
        this.username = username;
        this.password = password;
        this.groups = groups;



    }

    @Override
    public String toString() {
        return this.firstname + " " + this.lastname;
    }

    public static User connect(String username, String password) {
        return find("byUsernameAndPassword", username, password).first();
    }
}
